package com.kexio.common.exception;

/**
 * 系统异常
 * 用于处理系统级异常，如数据库连接失败、外部服务调用失败、配置错误等
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
public class SystemException extends BaseException {
    
    /**
     * 默认系统异常码
     */
    public static final Integer DEFAULT_CODE = 500;
    
    /**
     * 数据库异常
     */
    public static final Integer DATABASE_ERROR = 5001;
    
    /**
     * 缓存异常
     */
    public static final Integer CACHE_ERROR = 5002;
    
    /**
     * 外部服务异常
     */
    public static final Integer EXTERNAL_SERVICE_ERROR = 5003;
    
    /**
     * 配置异常
     */
    public static final Integer CONFIG_ERROR = 5004;
    
    /**
     * 文件操作异常
     */
    public static final Integer FILE_ERROR = 5005;
    
    /**
     * 网络异常
     */
    public static final Integer NETWORK_ERROR = 5006;
    
    /**
     * 认证异常
     */
    public static final Integer AUTHENTICATION_ERROR = 5007;
    
    /**
     * 授权异常
     */
    public static final Integer AUTHORIZATION_ERROR = 5008;
    
    public SystemException(String message) {
        super(DEFAULT_CODE, message);
    }
    
    public SystemException(Integer code, String message) {
        super(code, message);
    }
    
    public SystemException(String message, String detail) {
        super(DEFAULT_CODE, message, detail);
    }
    
    public SystemException(Integer code, String message, String detail) {
        super(code, message, detail);
    }
    
    public SystemException(String message, Throwable cause) {
        super(DEFAULT_CODE, message, cause);
    }
    
    public SystemException(Integer code, String message, Throwable cause) {
        super(code, message, cause);
    }
    
    // 快捷创建方法
    
    /**
     * 数据库异常
     */
    public static SystemException databaseError(String message) {
        return new SystemException(DATABASE_ERROR, message);
    }
    
    /**
     * 数据库异常，带原因
     */
    public static SystemException databaseError(String message, Throwable cause) {
        return new SystemException(DATABASE_ERROR, message, cause);
    }
    
    /**
     * 缓存异常
     */
    public static SystemException cacheError(String message) {
        return new SystemException(CACHE_ERROR, message);
    }
    
    /**
     * 缓存异常，带原因
     */
    public static SystemException cacheError(String message, Throwable cause) {
        return new SystemException(CACHE_ERROR, message, cause);
    }
    
    /**
     * 外部服务异常
     */
    public static SystemException externalServiceError(String message) {
        return new SystemException(EXTERNAL_SERVICE_ERROR, message);
    }
    
    /**
     * 外部服务异常，带原因
     */
    public static SystemException externalServiceError(String message, Throwable cause) {
        return new SystemException(EXTERNAL_SERVICE_ERROR, message, cause);
    }
    
    /**
     * 配置异常
     */
    public static SystemException configError(String message) {
        return new SystemException(CONFIG_ERROR, message);
    }
    
    /**
     * 文件操作异常
     */
    public static SystemException fileError(String message) {
        return new SystemException(FILE_ERROR, message);
    }
    
    /**
     * 文件操作异常，带原因
     */
    public static SystemException fileError(String message, Throwable cause) {
        return new SystemException(FILE_ERROR, message, cause);
    }
    
    /**
     * 网络异常
     */
    public static SystemException networkError(String message) {
        return new SystemException(NETWORK_ERROR, message);
    }
    
    /**
     * 网络异常，带原因
     */
    public static SystemException networkError(String message, Throwable cause) {
        return new SystemException(NETWORK_ERROR, message, cause);
    }
    
    /**
     * 认证异常
     */
    public static SystemException authenticationError(String message) {
        return new SystemException(AUTHENTICATION_ERROR, message);
    }
    
    /**
     * 授权异常
     */
    public static SystemException authorizationError(String message) {
        return new SystemException(AUTHORIZATION_ERROR, message);
    }
}
